// color
#include<bits/stdc++.h>
using namespace std;


int arr[200005];

int main(){
	
    freopen("color1.in", "r", stdin);
    freopen("color.out", "w", stdout);
    //README
    
    int T, n;
    long long res = 0;
    
    cin>>T;
    for(int g = 1; g <= T; g++){
		res = 0;
		for(int i = 1; i < 200005; i++){
			arr[i] = 0;
		}
		
		cin>>n;
		for(int i = 1; i <= n; i++){
			scanf("%d", &arr[i]);
		}
		
		for(int i = n; i >= 2; i--){
			if(arr[i] != 0){
				for(int j = i-1; j >= 1; j--){
					if(arr[j] == arr[i]){
						res += arr[i];
						arr[j] = 0;
						break;
					}
				}
			}
		}
		
		cout<<res<<endl;
	}
	
    return 0;
}
